package com.ebolib.base;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;

import com.ebo.commonlib.utils.I_Share;
import com.ebo.corelib.ui.BaseActivity;
import com.ebo.corelib.ui.mvp.BasePresenter;
import com.ebo.corelib.utils.AnimeUtils;
import com.ebolib.net.OutDateEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;



/**
 * Created by admin on 2018/5/14.
 */

public abstract class MyBaseActivity<P extends BasePresenter> extends BaseActivity<P> {

    private Bundle mTransAnimation;

    @Override
    protected void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
    }

    public void clearTransAnimation() {
        mTransAnimation = null;
    }

    public void setTransAnimation(Bundle transAnimation) {
        mTransAnimation = transAnimation;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTransAnimation = AnimeUtils.sceneTransAnime(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onOutDate(OutDateEvent event) {
        onOutDatePreExcuted();
        I_Share.setIsLogin(false);
        Intent intent = new Intent();
//        intent.setClass(this, LoginActivity.class);
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
//                Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra("drawback", true);
        startActivity(intent);
    }

    protected void onOutDatePreExcuted() {

    }


    @Override
    public void finish() {
        super.finish();
        AnimeUtils.sceneTransAnimeExit(this);
    }


    @Override
    public void startActivity(Intent intent) {
        if (Build.VERSION.SDK_INT < 16 || mTransAnimation == null) {
            super.startActivity(intent);
        } else {
            ActivityCompat.startActivity(this, intent, mTransAnimation);
        }
    }


    @Override
    public void startActivityForResult(Intent intent, int requestCode) {
        if (Build.VERSION.SDK_INT < 16 || mTransAnimation == null) {
            super.startActivityForResult(intent, requestCode);
        } else {
            ActivityCompat.startActivityForResult(this, intent, requestCode, mTransAnimation);
        }
    }


}
